package com.yq.socket1.day1.v4;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;


/**
 * @author 3307235355@qq.com
 * @description
 * @since 2022/07/01 10:52
 */
public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8888);
        Socket socket = serverSocket.accept();

        FileOutputStream outFile = new FileOutputStream("copy.jpg");
        InputStream in = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int read;
        while ((read=in.read(bytes))!=-1){
            outFile.write(bytes,0,read);
        }

        //client
        OutputStream out = socket.getOutputStream();
        out.write("文件上传成功过".getBytes());


        outFile.close();
        socket.close();
        serverSocket.close();


    }
}
